<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // Proxy(代理) 代理对象的各种操作

        const zhoujielun = {
            name: '周杰伦',
            age: 18,
            phone: '1234567890'
        }

        const proxy = new Proxy(zhoujielun, {
            get(target, key, receiver) {
                console.log('get', key);
                if (key === 'phone') {
                    return '经纪人：12345622290'
                }
                return target[key]
            },
            set(target, key, value, receiver) {
                console.log('set key:', key, '===', value);

                if (key === 'phone') {
                    return '12345622290'
                }
                target[key] = value
            },
            has(target, key) {
                console.log('has:', key);
                return key in target
            },
            deleteProperty: function (target, property) {
                console.log('delete:', property);
            },
            defineProperty: function (target, property, descriptor) {
                console.log('defineProperty:', property, descriptor);
                return true;
            },

        })

        console.log(proxy.phone, proxy.name, proxy.age);

        proxy.phone = '123'
        console.log(proxy.phone);

        console.log('has:', 'phone' in proxy);

        delete proxy.name

        proxy.abc = 123

        Object.defineProperty(proxy, 'bcd', {
            value: '456'
        })


    </script>
</body>

</html>